<template>

  <textarea style="width: 100%; height: 200px;" rows="10" cols="50"  v-model="str"  placeholder="请将数据放在此处"></textarea>
  <br/>
  <br/>
  <select v-model="selectedItem" style="width: 150px;height: 30px">
    <option value="">---请选择操作人姓名---</option>
<!--    <option value="朱思恒">朱思恒</option>-->
  </select>

  <br/><br/>
  <el-button type="primary" @click="test" :disabled="isLoading">数据录入按钮</el-button>

</template>

<script>
import axios from "axios";
import {ElMessage} from "element-plus"
export default {
  name: "DataLu",
  data(){
    return{
      str:"",
      selectedItem:"",
      isLoading:false
    }
  },methods:{
    test(){
      if (this.selectedItem.length!=0){
        this.isLoading = true;
        axios.post(`api/getfxptemployy?doName=${this.selectedItem}`,this.str,{
          headers: {
            'Content-Type': 'application/json; charset=UTF-8'
          }
        }).then((res)=>{
          if (res.data == '你正在重复添加数据'){
            ElMessage.error("你的操作已被取消，你正在重复添加数据");
          }else{
            ElMessage.success(res.data)
          }

        })
        .catch((error)=>{
          ElMessage.error("数据格式异常")
        })
        .finally(()=>{
          this.isLoading = false; // 无论请求成功或失败，都要在最终放开按钮
          this.str = '';
        })
      }else{
        ElMessage.warning("请选择操作人")
      }
    }
  }
}
</script>

<style scoped>
.textbox {
  width: 400px;
  height: 400px;
  padding: 5px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 5px;
  outline: none;
}
.textbox:focus {
  border-color: #007bff;
  box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}


</style>